import { InjectionKey } from 'vue';
import { createStore, useStore as baseUseStore, Store } from 'vuex';

export interface StateA {
  count: number;
  person: {
    name: string;
    age: number;
  };
}

export const key: InjectionKey<Store<StateA>> = Symbol();

export const store = createStore<StateA>({
  state: {
    count: 0,
    person: {
      name: 'moduleA',
      age: 12,
    },
  },
  mutations: {
    increment(state) {
      state.count++;
    },
  },
});

// 定义自己的 `useStore` 组合式函数
export function useStoreA() {
  return baseUseStore(key);
}
